package com.ruoyi.zhjd.laboratory.modules.furnacehthy.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.zhjd.laboratory.modules.furnacehthy.entity.ExperimentEntity;
import com.ruoyi.zhjd.laboratory.modules.furnacehthy.entity.ResultEntity;
import com.ruoyi.zhjd.laboratory.modules.furnacehthy.mapper.ExperimentMapper;
import com.ruoyi.zhjd.laboratory.modules.furnacehthy.mapper.ResultMapper;
import com.ruoyi.zhjd.laboratory.modules.furnacehthy.model.ExperimentModel;
import com.ruoyi.zhjd.laboratory.modules.furnacehthy.model.ResultModel;
import com.ruoyi.zhjd.laboratory.modules.furnacehthy.service.FurnaceHthyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 北京航天航宇燃烧炉实验数据采集
 */
@Service
public class FurnaceHthyServiceImpl extends ServiceImpl<ExperimentMapper, ExperimentEntity> implements FurnaceHthyService {

    @Autowired
    private ExperimentMapper experimentMapper;
    @Autowired
    private ResultMapper resultMapper;

    @Override
    public void saveCollectData(ExperimentModel experiment) {
        ExperimentEntity experimentEntity = BeanUtil.toBean(experiment, ExperimentEntity.class);
        experimentMapper.insert(experimentEntity);

        for (ResultModel result : experiment.getResultList()) {
            ResultEntity resultEntity = BeanUtil.toBean(result, ResultEntity.class);
            resultEntity.setParentPkId(experimentEntity.getPkId());
            resultMapper.insert(resultEntity);
        }
    }
}
